const mysql = require("mysql")

const options = {
    host: "localhost",
    user: "root",
    password: "",
    database: "userlist"
}
// 创建数据库连接
const sqlConnection = mysql.createConnection(options)
// 建立连接
sqlConnection.connect(err => {
    if(err) {
        console.log(err)
    } else {
        console.log("数据库连接成功...")
    }
})

function base(sql, data) {
    return new Promise((resolve, reject) => {
        sqlConnection.query(sql, data, (err, result) => {
            if(err) {
                reject(err)
            } else {
                resolve(result)
            }
        })
    })
}

module.exports = base